package IO;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws Exception{
         /*构造器第一个参数为流，第二个参数可以传入Boolean类型的数据来不是是否打开自动刷新功能*/                                   /*字符缓冲流*/                  /*字符转换流*/                     /*文件字节流*/
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("pw.txt"), StandardCharsets.UTF_8)),true);
        Scanner scanner =new Scanner(System.in);
        System.out.println("请开始输入内容，单独输入exit时退出");
        while (true){
            String len = scanner.nextLine();
            if ("exit".equals(len)){
                break;
            }
            pw.println(len);
        }
        System.out.println("结束");
        pw.close();
    }
}
